<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/28/028
 * Time: 10:57
 */

namespace app\api\controller\v1;

use app\api\controller\BaseController;
use \app\api\model\Member as MemberModel;
use \app\api\model\MemberRoleInfo as MemberRoleInfoModel;
use app\api\model\Registration as RegistrationModel;
use app\api\model\Certification as CertificationModel;
use app\api\model\MemberFigureMeasureData as MemberFigureMeasureDataModel;
use app\api\validate\CertificationValidate;
use app\api\validate\MemberRoleInfo as MemberRoleInfoValidate;
use \app\lib\exception\MemberException;
use app\lib\exception\SuccessMessage;

class Member extends BaseController {

    /**
     * 获取用户个人中心数据
     * @return array|null|\PDOStatement|string|\think\Model
     * @throws MemberException
     */
    public function info() {
        // 获取用户信息
        $member = MemberModel::info();
        if (!$member) {
            throw new MemberException();
        }

//        // 检查签到
        $check_registration = RegistrationModel::check_registration($member['id']);
        $member['check_registration'] = $check_registration;

        return $member;
    }

    /**
     * 保存个人信息
     * @return \think\response\Json
     */
    public function update_member_role_info() {
        $login_validate = new MemberRoleInfoValidate();
        // 验证参数
        $login_validate->goCheck();

        // 根据验证规则获取参数
        $params = $login_validate->getDataByRule(input('post.'));

        MemberRoleInfoModel::updateMemberRoleInfoByField($params);

        return json(new SuccessMessage(), 201);
    }

    /**
     * 实名认证
     * @return \think\response\View
     */
    public function certification() {
        $login_validate = new CertificationValidate();

        // 验证参数
        $login_validate->goCheck();

        $params = $login_validate->getDataByRule(input('post.'));

        CertificationModel::save_member_certification($params);
        return json(new SuccessMessage(), 201);
    }

    /**
     * 获取团队信息
     * @return array
     */
    public function memberTeam() {
        return MemberModel::memberTeam();
    }
}